﻿#include <iostream>
#include <vector>
#include <queue>
#include <string>
using namespace std;

class Solution
{
public:
    // 2208. 将数组和减半的最少操作次数
    int halveArray(vector<int>& nums)
    {
        priority_queue<double> q;
        double sum = 0.0;
        int count = 0;
        for (auto x : nums)
        {
            sum += x;
            q.push(x);
        }
        sum /= 2;
        while (sum > 0)
        {
            double tmp = q.top();
            q.pop();
            tmp /= 2;
            sum -= tmp;
            q.push(tmp);
            count++;
        }
        return count;
    }

    // 179. 最大数
    string largestNumber(vector<int>& nums)
    {
        vector<string> str;
        for (auto x : nums)
            str.push_back(to_string(x));

        sort(str.begin(), str.end(), [&](const string s1, const string s2)
            {
                return s1 + s2 > s2 + s1;
            });

        string ret;
        for (auto s : str)
            ret += s;

        if (ret[0] == '0')
            return "0";
        return ret;
    }
};

int main()
{
    vector<int> v{ 5,19,8,1 };
    cout << Solution().halveArray(v) << endl;

    return 0;
}